import { services } from '@/config'

const validateBudget = (rule, value, callback) => {
  if (value !== '') {
    const reg = /[\u4e00-\u9fa5]/g
    if (reg.test(value)) {
      callback(new Error('请输入字母或数字组成的编号'))
    } else {
      callback()
    }
  } else {
    callback()
  }
}

export const tableOptionBill = {
  labelPosition: 'left',
  labelSuffix: '：',
  labelWidth: 120,
  gutter: 0,
  menuBtn: true,
  submitBtn: true,
  submitText: '提交',
  emptyBtn: true,
  emptyText: '清空',
  menuPosition: 'center',
  align: 'center',
  index: true,
  border: true,
  stripe: true,
  menuAlign: 'center',
  indexLabel: '序号',
  searchMenuSpan: 4,
  viewBtn: true,
  searchShow: false,
  selection: true,
  addBtn: false,
  menu: false,
  column: [
    {
      type: 'input',
      label: '主键ID',
      prop: 'id',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '唯一编码（用于关联附件）',
      prop: 'unid',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建人ID',
      prop: 'createId',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建人姓名',
      prop: 'createBy',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建时间',
      prop: 'createTime',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建人所属OU的ID',
      prop: 'deptId',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建人所属OU的全称',
      prop: 'deptFullname',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '最后修改人信息',
      prop: 'updateBy',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '最后修改时间',
      prop: 'updateTime',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '租户ID',
      prop: 'tenantId',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '数据删除标记',
      prop: 'delFlag',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'tree',
      label: '预算',
      prop: 'budgetId',
      searchLabelWidth: 85,
      search: true,
      span: 24,
      dicUrl: `${services.assetService}fyassetbudget/budgetTree`,
      dicMethod: 'get',
      props: { label: 'name', value: 'id' },
      hide: true
    },
    {
      type: 'input',
      label: '预算编号',
      prop: 'budgetNumber',
      span: 12,
      display: false,
      editDisabled: true
    },
    {
      type: 'input',
      label: '发票名称',
      prop: 'name',
      searchLabelWidth: 85,
      searchSpan: 6,
      span: 12,
      required: true,
      search: true,
      fixed: true,
      width: 120,
      maxlength: 120,
      rules: [
        {
          required: true,
          message: '请填写发票名称'
        }
      ]
    },
    {
      type: 'input',
      label: '发票编号', // （编号用户填了就按他的不填就自增长）
      prop: 'contractId',
      span: 12,
      width: 120,
      search: true,
      searchLabelWidth: 85,
      maxlength: 120,
      rules: [{ validator: validateBudget, trigger: 'blur' }]
    },
    {
      type: 'select',
      label: '供应商',
      prop: 'supplierId',
      span: 12,
      dicUrl: `${services.assetService}fyassetsupplier/tree`,
      dicMethod: 'get',
      props: { label: 'name', value: 'id' },
      hide: true,
      dicQuery: { type: 'V' }
    },
    {
      type: 'select',
      label: '类型', // （CONTRACT：发票、BILL：发票）
      prop: 'type',
      span: 12,
      hide: true,
      value: 'BILL', // contract_type_host
      addDisabled: true,
      editDisabled: true,
      dicUrl: `${services.adminService}dict/type/contract_type_host`,
      dicMethod: 'get',
      props: { label: 'label', value: 'value' },
      required: true,
      rules: [
        {
          required: true,
          message: '请选择类型'
        }
      ]
    },
    {
      type: 'select',
      label: '状态', // ：0：草稿，1：审批中， 3：已归档  4：发票失效 5：发票作废
      prop: 'status',
      span: 12,
      dicUrl: `${services.adminService}dict/type/contract_status`,
      dicMethod: 'get',
      props: { label: 'label', value: 'value' },
      required: true,
      search: true,
      searchLabelWidth: 60,
      searchSpan: 4,
      rules: [
        {
          required: true,
          message: '请选择状态'
        }
      ]
    },
    {
      type: 'textarea',
      label: '条款',
      prop: 'terms',
      span: 24,
      maxlength: 3000,
      required: true,
      hide: true,
      rules: [
        {
          required: true,
          message: '请填写条款'
        }
      ]
    },
    {
      type: 'select',
      label: '发票类型', // （ASSET：资产发票、HOUSE：房屋）
      prop: 'contractType',
      span: 12,
      search: true,
      searchLabelWidth: 85,
      dicUrl: `${services.adminService}dict/type/contract_type_rate`,
      dicMethod: 'get',
      props: { label: 'label', value: 'value' },
      required: true,
      rules: [
        {
          required: true,
          message: '请选择发票类型'
        }
      ]
    },
    {
      type: 'input',
      label: '签订地点',
      prop: 'contractSignplace',
      span: 12,
      search: true,
      searchLabelWidth: 85,
      required: true,
      width: 160,
      rules: [
        {
          required: true,
          message: '请填写签订地点'
        }
      ]
    },
    {
      type: 'date',
      label: '签订时间',
      prop: 'contractSigndate',
      span: 12,
      width: 85,
      search: true,
      searchRange: true,
      searchLabelWidth: 85,
      searchSpan: 12,
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      required: true,
      rules: [
        {
          required: true,
          message: '请填写签订时间'
        }
      ]
    },
    {
      type: 'date',
      label: '生效时间',
      prop: 'effectiveDate',
      span: 12,
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      width: 85,
      required: true,
      rules: [
        {
          required: true,
          message: '请填写生效时间'
        }
      ]
    },
    {
      type: 'date',
      label: '结束时间',
      prop: 'expirationDate',
      span: 12,
      width: 85,
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      required: true,
      rules: [
        {
          required: true,
          message: '请填写结束时间'
        }
      ]
    },
    {
      type: 'number',
      label: '金额',
      prop: 'amount',
      span: 12,
      required: true,
      value: 0,
      rules: [
        {
          required: true,
          message: '请填写金额'
        }
      ]
    },
    {
      type: 'tree',
      label: '签订人员',
      prop: 'responsemanId',
      span: 12,
      hide: true,
      props: { label: 'name', value: 'id' },
      dicUrl: `${services.adminService}user/tree`,
      dicMethod: 'get'
    },
    {
      type: 'input',
      label: '签订人名称',
      width: 90,
      prop: 'responsemanName',
      span: 12,
      display: false
    },
    {
      type: 'textarea',
      label: '备注',
      prop: 'remarks',
      span: 24,
      width: 120
    },
    {
      type: 'input',
      label: '供应商名称',
      prop: 'supplierName',
      search: true,
      searchLabelWidth: 110,
      width: 90,
      span: 12,
      display: false
    },
    {
      label: '附件信息',
      prop: 'uploadPage',
      type: 'input',
      formslot: true,
      slot: true,
      span: 24,
      hide: true
    }
  ]
}
